package demo1;

import java.io.*;
import java.util.Scanner;

/**
 * Created with Intellij IDEA.
 * Description:
 * User: 33013
 * Date: 2023-10-07
 * Time: 16:02
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入源路径：");
        String str = scanner.nextLine();
        File src = new File(str);
        if (!src.isFile()){
            return;
        }
        System.out.println("请输入目标路径：");
        String str1 = scanner.nextLine();
        File desc = new File(str1);
        if(!desc.getParentFile().isDirectory()){
            return;
        }
        try(InputStream inputStream = new FileInputStream(src);
            OutputStream outputStream = new FileOutputStream(desc)) {
            while (true){
                byte[] bytes = new byte[1024];
                int n = inputStream.read(bytes);
                if(n == -1){
                    break;
                }
                outputStream.write(bytes, 0, n);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
